package com.huluspace.apicall.controller;


import com.huluspace.apicall.dto.WeatherResponse;
import com.huluspace.apicall.service.WeatherService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class WeatherController {

  // 构造器方式注入依赖，保证依赖不可变（final）
  private final WeatherService weatherService;
  public WeatherController(WeatherService weatherService) {
    this.weatherService = weatherService;
  }

  @GetMapping("/weather")
  public WeatherResponse getWeather(@RequestParam("location") String location) {
    return weatherService.getWeatherByCity(location);
  }
}
